﻿// --------------------------------
// <copyright file="TableManager.cs" company="TRONSoft">
//     Copyright (c) TRONSoft.
// </copyright>
// <license>
//   This source code is subject to terms and conditions of the Microsoft
//   Public License. A copy of the license can be found in the License.html
//   file at the root of this distribution. If you cannot locate the
//   Microsoft Public License, please send an email to dlr@microsoft.com.
//   By using this source code in any fashion, you are agreeing to be bound 
//   by the terms of the Microsoft Public License. You must not remove this
//   notice, or any other, from this software.
// </license>
// <author>Tron</author>
// ---------------------------------

using System;
using System.Data;
using System.IO;
using System.Xml;

namespace Tronsoft.Actucal.Tables
{
    public class TableManager
    {
        private static readonly TableManager instance = new TableManager();
        private readonly TableCollection tables = new TableCollection();

        public static TableManager Instance
        {
            get { return instance; }
        }

        public TableCollection Tables
        {
            get { return tables; }
        }

        public void Clear()
        {
            tables.Clear();
        }

        public TableDefinition AddTable(string tableName)
        {
            if (string.IsNullOrEmpty(tableName)) throw new ArgumentNullException("tableName");

            if (!Tables.Contains(tableName))
            {
                return Tables.Add(tableName);
            }

            return Tables[tableName];
        }

        #region WriteXml
        public void WriteXml(Stream stream)
        {
            Tables.WriteXml(stream);
        }

        public void WriteXml(TextWriter writer)
        {
            Tables.WriteXml(writer);
        }

        public void WriteXml(XmlWriter writer)
        {
            Tables.WriteXml(writer);
        }

        public void WriteXml(string fileName)
        {
            Tables.WriteXml(fileName);
        }

        public void WriteXml(Stream stream, XmlWriteMode mode)
        {
            Tables.WriteXml(stream, mode);
        }

        public void WriteXml(TextWriter writer, XmlWriteMode mode)
        {
            Tables.WriteXml(writer, mode);
        }

        public void WriteXml(XmlWriter writer, XmlWriteMode mode)
        {
            Tables.WriteXml(writer, mode);
        }

        public void WriteXml(string fileName, XmlWriteMode mode)
        {
            Tables.WriteXml(fileName, mode);
        }
        #endregion

        #region ReadXml
        public XmlReadMode ReadXml(Stream stream)
        {
            return Tables.ReadXml(stream);
        }

        public XmlReadMode ReadXml(XmlReader reader)
        {
            return Tables.ReadXml(reader);
        }

        public XmlReadMode ReadXml(TextReader reader)
        {
            return Tables.ReadXml(reader);
        }

        public XmlReadMode ReadXml(string fileName)
        {
            return Tables.ReadXml(fileName);
        }

        public XmlReadMode ReadXml(Stream stream, XmlReadMode mode)
        {
            return Tables.ReadXml(stream, mode);
        }

        public XmlReadMode ReadXml(XmlReader reader, XmlReadMode mode)
        {
            return Tables.ReadXml(reader, mode);
        }

        public XmlReadMode ReadXml(TextReader reader, XmlReadMode mode)
        {
            return Tables.ReadXml(reader, mode);
        }

        public XmlReadMode ReadXml(string fileName, XmlReadMode mode)
        {
            return Tables.ReadXml(fileName, mode);
        }
        #endregion
    }
}